package com.jsyh.maidu.presenter;

import android.content.Context;

import com.jsyh.maidu.config.ConfigValue;
import com.jsyh.maidu.http.BaseDelegate;
import com.jsyh.maidu.http.OkHttpClientManager;
import com.jsyh.maidu.model.BaseModel;
import com.jsyh.maidu.model.BonusModel;
import com.jsyh.maidu.views.MeBounsView;
import com.squareup.okhttp.Request;

import java.util.HashMap;
import java.util.Map;


public class MeBounsPresenter extends BasePresenter {

    private MeBounsView meBounsView;

    public MeBounsPresenter(MeBounsView meBounsView) {
        this.meBounsView = meBounsView;
    }

    public void getBonusList(Context context, String key, String page) {
        initLoadDialog(context);
        mLoadingDialog.show();
        Map<String, String> param = new HashMap<>();
        param.put("key", key);
        param.put("page", page);
        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "bonus/all", param, new BaseDelegate.ResultCallback<BonusModel>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                mLoadingDialog.dismiss();
            }

            @Override
            public void onResponse(BonusModel response, Object tag) {
                mLoadingDialog.dismiss();
                meBounsView.getBonus(response);
            }
        });
    }

    public void addBonus(Context context, String key, String bonus_sn){

        initLoadDialog(context);
        mLoadingDialog.show();
        Map<String, String> param = new HashMap<>();
        param.put("key", key);
        param.put("bonus_sn", bonus_sn);
        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "bonus/add", param, new BaseDelegate.ResultCallback<BaseModel>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                mLoadingDialog.dismiss();
            }

            @Override
            public void onResponse(BaseModel response, Object tag) {
                mLoadingDialog.dismiss();
                meBounsView.getAddResult(response);

            }
        });

    }
}
